/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       override_input_handler.cpp

	$Header: /game/override_input_handler.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>

#include "override_input_handler.h"

#include "bound_handler.h"
#include "windows_game.h"

// ---------------------------------------------------------------
// class to set a callback handler for any mouse or keyboard press
// ---------------------------------------------------------------
t_override_input::t_override_input() 
: m_input_handler(NULL)
{
	common_constructor();
}

t_override_input::t_override_input( bool has_mouse_event )
{
	common_constructor();
	m_handle_mouse_event = has_mouse_event;
}

void	t_override_input::common_constructor()
{
	m_handle_mouse_event=true;

	t_mouse_event_handler mouse_handler;
	t_mouse_event_handler no_action_mouse_handler;

	mouse_handler = bound_handler( *this, &t_override_input::mouse_event );
	no_action_mouse_handler = bound_handler( *this, &t_override_input::non_handled_mouse_event );

	set_left_button_down_handler( no_action_mouse_handler );
	set_left_button_up_handler( mouse_handler );
	set_left_button_double_clicked_handler( mouse_handler );
	set_right_button_down_handler( no_action_mouse_handler );
	set_right_button_up_handler( mouse_handler );
	set_right_button_double_clicked_handler( mouse_handler );
}

// ---------------------------------------------------------------
// class to set a callback handler for any mouse or keyboard press
// ---------------------------------------------------------------
t_override_input::~t_override_input()
{
	set_left_button_down_handler( NULL );
	set_left_button_up_handler( NULL );
	set_left_button_double_clicked_handler( NULL );
	set_right_button_down_handler( NULL );
	set_right_button_up_handler( NULL );
	set_right_button_double_clicked_handler( NULL );
}

// ---------------------------------------------------------------
// class to set a callback handler for any mouse or keyboard press
// ---------------------------------------------------------------
void t_override_input::mouse_event( t_mouse_event* event, bool* result )
{
	if (m_handle_mouse_event)
		m_input_handler();
	*result = true;
}

// ---------------------------------------------------------------
// class to set a callback handler for any mouse or keyboard press
// ---------------------------------------------------------------
void t_override_input::non_handled_mouse_event( t_mouse_event* event, bool* result )
{
	*result = true;
}

// --------------------------------------------------------
// --------------------------------------------------------